home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The CICA Windows Explosion!
/
The CICA Windows Explosion! - Disc 2.iso
/
programr
/
cstr22.zip
/
CSTR20.H_
/
CSTR20.H
Wrap
C/C++ Source or Header
|
1994-12-11
|
20KB
|
395 lines
// --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//
// CSTR20.H
// String Studio 2.02 - Header file for CSTR20A.CPP, CSTR20B.CPP ( or CSTR20R.LIB or CSTR20W.LIB )
// 08.dec.1994
// «HEXANET, Written by Denis CHEVRON,
// COPYRIGHT HEXANET 1993, 1994, ALL RIGHTS RESERVED
// You can distribute this file as long as you distribute
// the full CSTR package ( not the CSTR20A.CPP nor CSTR20B.CPP files! )
// --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Current implementation is for MFC for DOS or WINDOWS (16bits).
// CSTR20W.LIB was compiled with Visual C++ 1.5 under the Windows static large model
// You must include "stdafx.h" or <afx.h> before you include this file.
// CSTR20R.LIB was compiled with Visual C++ 1.5 under the DOS real mode large model.
// To rebuild this library you will need LAFXCR.LIB and maybe you need to build it from
// the MFC source code...
//
// --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//
// If you are a registered user, you will define _REGISTERED in your STDAFX.H precompiled header before
// you compile this file to avoid the nag screens.
// If you use this library with the source code with QuickWin, undefine _WINDOWS and define _DOS.
// --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//
// Attn. to 1.x users...
// Some old functions were re-written ( like the () operator, From, To, Extract ) so, have a look at
// this file before you compile with this new library.
// --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//
// GLOBAL FUNCTIONS ( Afx... )
// Infos: AfxGetFreeResRate, AfxGetFreeResValue
// User' s config infos: AfxGetPrecision, AfxGetDecimalPoint, AfxGetThousandsSeparator,
// AfxGetShortDateFormat, AfxGetShortDateFormat, AfxGetLongDateFormat
// CTL3D wrappers: AfxCtl3dLoad, AfxCtl3dUnload, AfxCtl3dNewColors
// Windows coordinates: AfxWriteWindowPos, AfxGetWindowPos
// Math: AfxRoundToInt, AfxRound
// Misc.: AfxFindWordInFile, AfxCheckFileName, AfxIsDateValid
//
// CONSTRUCTORS
// Same as CString, plus a constructor which uses a string resource ID.
//
// INPUT
// From ( long / ulong / int / UINT / double ( precision ) / CTime )
// FromCurrentTime( mask )
// FromFileTime
// FromRes
//
// OUTPUT
// ToInt, ToUINT, ToLong, ToULong, ToFloat, ToDouble, ToTime
//
// OPERATIONS
// Trim : Trim, TrimBegin, TrimEnd
// Find: Count, FindWord, FindWordInMultilineBuffer
// Extract/Insert: Extract, ExtractToBegin, ExtractToEnd, Insert, Delete, Replace
// Operators: () (replace []) , GetBuffer
//
// OTHERS
// Blank, Replicate, AddLF, FirstUpper
//
// NUMBERS
// IsDigit, IsInRange, Round
//
// INTERFACE
// ToCtl, FromCtl, MB, CheckSize, CheckDirSize
//
// FILES
// ToFile, FromFile, ToIni, FromIni
//
// FILE NAMES (2.0)
// Infos: IsFileName, IsPathName, IsFullFileName
// Extraction: GetPathValue, GetFileNameValue
// Test: CheckFullFileName, CheckFileExtension, DoesFileExist, DoesDirExist
// Misc: GetTempFileName
//
// DIRECTORIES (2.0)
// ChDir, MkDir, GetAppDir, GetWinDir, GetWinSysDir, GetThisDir
//
// CHARACTERS (2.0)
// Infos: IsCharUpper, IsCharLower, IsCharAlpha, IsCharAlphaNum, IsNumeric, IsSpace
// Modif: MakeCharUpper, MakeCharLower
//
// GDI (2.0)
// GetTextWidth, GetTextHeight, TabbedTextOut
//
// WINDOWS SPECIFIC (2.0)
// GetWindowTitle, GetClassName, GetWinfileAssociation
//
// CTim class (2.0)
// Constructors: same as CTime
// Build: Build, FromFile
// Modification: SetDay, SetMonth, SetYear, SetHour, SetMin, SetHour, IncDay, IncSec, IncMin, IncHour
// Infos: IsLeapYear, IsLastDay
//
//
// --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#ifndef __cplusplus
#error require C++ compilation (use a .cpp suffix)
#endif
#ifndef _CSTR
#define _CSTR
#endif
#ifndef _CSTR20
#define _CSTR20
#endif
#ifdef _DOS
#define _REGISTERED // No nag screen with DOS...
#define TA_LEFT 0x0000
#define TA_RIGHT 0x0002
#define TA_CENTER 0x0006
#pragma message("String Studio 2.0: Using the DOS version...")
#else
#ifdef _REGISTERED
#pragma message("String Studio 2.0 (REGISTERED): Using the Windows version...")
#else
#pragma message("String Studio 2.0 (UNREGISTERED): Using the Windows version...")
#endif
#endif
// ------------------------------------ NEW GLOBAL FUNCTIONS (2.0) -----------------------------------------------
#ifdef _WINDOWS
#define FREERES_GLOBAL 0 // System
#define FREERES_USER 1
#define FREERES_GDI 2
#define FREERES_MEM 3
#define FREERES_DISK 4 // in Kb.
extern UINT AfxGetFreeResRate( int iResCode );
extern unsigned long AfxGetFreeResValue( int iResCode );
extern int AfxGetPrecision();
class CStr;
extern CStr AfxGetDecimalPoint();
extern CStr AfxGetThousandsSeparator();
extern CString AfxGetShortDateFormat();
extern CString AfxGetLongDateFormat();
// Ctl3D ( release 2.0 only ) wrappers for the TRUE MFC applications
#define AFXCTL3D_OK 0 // Ok to use CTL3D
#define AFXCTL3D_NOTFOUND 1 // The user doesn' t get this DLL
#define AFXCTL3D_BADDLL 2 // Error
#define AFXCTL3D_ERROR 3 // Error
#ifndef CTL3D_ALL
#define CTL3D_ALL 0xffff
#endif
extern "C" int AfxCtl3dLoad( );
extern "C" BOOL AfxCtl3dUnload( );
extern "C" BOOL AfxCtl3dNewColors( );
// Window position functions
extern BOOL AfxWriteWindowPos( HWND hWnd , BOOL bUseParent = FALSE, LPCSTR szWindowName = "Main", LPCSTR szIni = NULL );
extern RECT AfxGetWindowPos( HWND hWnd = NULL, LPCSTR szWindowName = "Main", LPCSTR szIni = NULL, BOOL bMove = TRUE, BOOL bSize = FALSE);
extern BOOL AfxCenterWindow( CWnd* pWnd, BOOL bAbsolute = TRUE );
// Maybe the following functions will simplify your MFC dialogs programming...
extern BOOL AfxEnableDlgItem( CWnd* pWnd, UINT id = 1, BOOL bEnabled = TRUE );
extern BOOL AfxEnableOK( CWnd* pWnd, BOOL bEnabled = TRUE);
extern BOOL AfxEnableCANCEL( CWnd* pWnd, BOOL bEnabled = TRUE);
extern void AfxSetFocus( CWnd* pWnd, UINT id = 1 );
extern void AfxSetDefButton( CWnd* pWnd, UINT id = 1);
extern void AfxActivateEdit( CWnd* pWnd, UINT id );
#endif // windows
#define AfxRoundToInt(x) floor((x)+0.5)
extern double AfxRound( double x, int precision = 2);
extern BOOL AfxFindWordInFile( LPCSTR szFile, LPCSTR szWord, unsigned long iFromLine = 0L, int iFromCursor = 0,
unsigned long* rLineValue = NULL, int* rCursorValue =NULL, BOOL bExact = TRUE, BOOL bMatchCase = FALSE );
extern BOOL AfxCheckFileName( CString& sValue, BOOL bNoWildCards = TRUE);
extern BOOL AfxIsDateValid( int iYear, int iMonth, int iDay );
// ----------------------------------------------------------------------------------------------------------------------------------
typedef signed long SLong;
class CStr : public CString
{
public:
#ifdef _REGISTERED
CStr( void ): CString( ) {};
CStr( const CString& stringSrc): CString( stringSrc ) {};
CStr( char ch, int nRepeat = 1): CString(ch, nRepeat ) {};
CStr( const char* psz): CString( psz ) {};
CStr( const char* pch, int nLength): CString( pch, nLength ) {};
#ifdef _WINDOWS
CStr( UINT iStringID, HINSTANCE hInstance = NULL ): CString()
{
if ( hInstance == NULL ) this->LoadString ( (UINT)iStringID);
else
{
::LoadString( hInstance, (UINT)iStringID, this->GetBuffer(256), 256 );
this->ReleaseBuffer();
}
};
#endif
#else
CStr( void );
CStr( const CString& stringSrc);
CStr( char ch, int nRepeat = 1);
CStr( const char* psz);
CStr( const char* pch, int nLength);
#ifdef _WINDOWS
CStr( UINT iStringID, HINSTANCE hInstance = NULL );
#endif
#endif
CString Trim( void );
CString TrimBegin( void );
CString TrimEnd( void );
unsigned int Count( LPCSTR szSubString ) const;
unsigned int Count( char szSubString ) const;
CString From( long data, int base = 10, LPCSTR szSeparator = ",");
CString From( unsigned long data, int base = 10, LPCSTR szSeparator = ",");
CString From( int data, int base = 10, LPCSTR szSeparator = ",");
CString From( unsigned int data, int base = 10, LPCSTR szSeparator = ","); // 2.0
CString From( double data, int precision = 2, LPCSTR szSeparator = ",", LPCSTR szDecimalPoint = "." );
// --------------------------------- NEW FUNCTIONS (2.0) SEE CSTR20B.CPP -------------------------------
// Files and Dirs
BOOL IsFileName( BOOL bAllowWildCards = FALSE ) const;
BOOL IsPathName( ) const;
BOOL IsFullFileName( BOOL bNoWildCards = TRUE ) const;
CStr GetPathValue( );
CStr GetFileNameValue( );
CStr CheckFullFileName( BOOL bNoWildCards = TRUE, BOOL bAddSlash =FALSE);
CStr CheckFileExtension( LPCSTR szExtension, BOOL bForceExtension = FALSE);
BOOL ChDir( BOOL bIncludesFName = FALSE, BOOL bCreateDir = FALSE) const;
BOOL MkDir( BOOL bIncFile = FALSE) const;
BOOL DoesFileExist( ) const;
BOOL DoesDirExist( BOOL bIncFile = FALSE) const;
#ifdef _WINDOWS
CStr GetAppDir( LPCSTR szAppName = NULL );
CStr GetWinDir( );
CStr GetWinSysDir( );
#endif
CStr GetThisDir( );
CStr GetTempFileName( );
CStr GetTempDir();
// Character informations
BOOL IsCharUpper( int iIndex = 0) const;
BOOL IsCharLower( int iIndex =0) const;
BOOL IsCharAlpha( int iIndex =0) const;
BOOL IsCharAlphaNum( int iIndex =0) const;
BOOL IsCharNumeric( int iIndex =0) const;
BOOL IsSpace( int iIndex =0) const;
// Numeric datas format
CStr NumFormat( double dValue, LPCSTR szFormat = "###,###,###,###.00;-###,###,###,###.00; ", LPCSTR szDecimalPoint = ".", LPCSTR szThousandSeparator ="," );
CStr NumUnformat( LPCSTR szDecimalPoint = "." );
// Alignment function
CStr Align( int aMode, int iSize );
// Character modificattions
CStr MakeCharUpper( int iIndex =0);
CStr MakeCharLower( int iIndex =0);
// Extract like functions
CStr ExtractToEnd( int iFrom, char szSeparator );
CStr ExtractToEnd( int iFrom, LPCSTR szSeparator = ";" );
CStr ExtractToBegin( int iFrom, char szSeparator );
CStr ExtractToBegin( int iFrom, LPCSTR szSeparator = ";" );
// Find a word
int FindWord( LPCSTR szWord, int iFrom = 0, BOOL bExact = TRUE, BOOL bMatchCase =FALSE) const;
BOOL FindWordInMultilineBuffer( LPCSTR szWord, unsigned long iFromLine = 0L, int iFromCursor = 0,
unsigned long* rLineValue = NULL, int* rCursorValue = NULL, BOOL bExact = TRUE, BOOL bMatchCase =FALSE ) const;
#ifdef _WINDOWS
CStr FromRes( UINT iStringID, HINSTANCE hInstance = NULL, LPCSTR szItem1 = NULL, LPCSTR szItem2 = NULL, LPCSTR szItem3 = NULL, LPCSTR szItem4 = NULL,
LPCSTR szItem5 = NULL, LPCSTR szItem6 = NULL, LPCSTR szItem7 = NULL, LPCSTR szItem8 = NULL, LPCSTR szItem9 = NULL );
int GetTextWidth( HDC hDC, int iTabCount = 0, int far* pTabList = NULL ) const;
int GetTextWidth( CDC* pDC , int iTabCount = 0, int far* pTabList = NULL ) const;
int GetTextWidth( CWnd* pWnd , int iTabCount = 0, int far* pTabList = NULL ) const;
int GetTextHeight( HDC hDC , int iTabCount = 0, int far* pTabList = NULL ) const;
int GetTextHeight( CDC* pDC , int iTabCount = 0, int far* pTabList = NULL ) const;
int GetTextHeight( CWnd* pWnd , int iTabCount = 0, int far* pTabList = NULL ) const;
CStr GetWindowTitle( CWnd* pWnd, BOOL bIncDocName = FALSE );
CStr GetWindowTitle( HWND hWnd, BOOL bIncDocName = FALSE );
CSize TabbedTextOut( CDC* pDC, int X, int Y, int iTabCount = 0, int far* TabList = NULL ) const;
CSize TabbedTextOut( CWnd* pWnd, int X, int Y, int iTabCount = 0, int far* TabList = NULL ) const;
int GetClassName( CWnd* pWnd );
int GetClassName( HWND hWnd );
CStr GetWinfileAssociation( LPCSTR szExtension );
int GetDlgItemText( CWnd* pWnd, UINT iControl );
#endif
// --------------------------------- OTHER METHODS -------------------------------
#if !defined(_AFXDLL) && !defined(_USRDLL)
CString From( CTime TimeValue, LPCSTR szFilter = "%m/%d/%y" ); // put %d/%m/%y if you' re french...
CString FromCurrentTime( LPCSTR szFilter = "%m/%d/%y" ); // put %d/%m/%y if you' re french...
CString FromFileTime( LPCSTR szFile, LPCSTR szFilter = "%m/%d/%y" ); // put %d/%m/%y if you' re french...
#else
#pragma message("String Studio 2.0: Some CStr CTime functions not available with _AFXDLL or _USRDLL!")
#endif
signed int ToInt( LPCSTR szSeparator = ",") const;
UINT ToUINT( LPCSTR szSeparator = ",") const;
signed long ToLong( LPCSTR szSeparator = ",") const;
unsigned long ToULong( LPCSTR szSeparator = ",") const;
float ToFloat( LPCSTR szSeparator = ",", LPCSTR szDecimalPoint = "." ) const;
double ToDouble( LPCSTR szSeparator = ",", LPCSTR szDecimalPoint = "." ) const;
// WARNING: the <ToTime> function use M instead of m for the month, others parameters
// are the same than _strftime C runtime function, and ToTime supports: [ D, Y, y, S ]
CTime ToTime( LPCSTR szFilter = "M/D/Y" ) const; // put y io. Y to use a date without century specification, put D/M/Y if you' re french...
CStr Delete( unsigned PFirst = 0, unsigned Plength = 0 );
CStr Replace( LPCSTR szOld, LPCSTR szNew = "" );
CStr Replace( char szOld, char szNew );
CStr Insert( LPCSTR szSub, int Pos = 0 );
CStr Insert( char szSub, int Pos = 0 );
CStr Extract( int Pos = 1, LPCSTR szDelimit = "\t" );
CStr Extract( int Pos, char szDelimit );
char& operator() (int Index ); // new 2.0: Replace the [] operator
virtual LPSTR CStr::GetBuffer( int size = 0);
CStr Round( LPCSTR szDecimalPoint = ".");
CStr FirstUpper( void );
CStr AddLF( void );
CStr Blank( void );
CStr Replicate( char cMotif = ' ', int iLen = 1 );
CStr CheckSize( int iLength = 255, BOOL bAddPoints = TRUE );
CStr CheckDirSize( int iLength = 60, BOOL bShift = TRUE );
BOOL IsDigit( LPCSTR szSeparator = ",", LPCSTR szDecimalPoint = "." ) const;
BOOL IsInRange( double dMini = 0, double dMaxi = 100 ) const;
CStr FromIni( LPCSTR szSection, LPCSTR szKey, LPCSTR szFile = NULL, int iSize = 512 );
void ToIni( LPCSTR szSection, LPCSTR szKey, LPCSTR szFile = NULL ) const;
CStr FromFile( LPCSTR szFile, BOOL bKeepString = FALSE, BOOL bAddPoints = TRUE );
BOOL ToFile( LPCSTR szFile, BOOL bAppend = TRUE ) const;
#ifdef _WINDOWS
void ToCtl( CWnd* pWnd, int iCtl, BOOL bAltMode = FALSE ) const;
CStr FromCtl( CWnd* pWnd, int iCtl );
int MB( CWnd* pWnd = NULL, LPCSTR szTitle = NULL, UINT mbType = MB_OK | MB_ICONINFORMATION ) const;
#endif
protected: // don' t call these functions! --------------------------------------------------------------------------------
LPSTR TrimTout( LPSTR str ); // TrimAll
LPSTR TrimAuDebut( LPSTR str ); // TrimBegin
LPSTR TrimALaFin( LPSTR str ); // TrimEnd
void FromDouble( LPSTR pStr, double data, int precision, LPCSTR szDecimalPoint = "." );
char GarbageChar;
CStr NumberFormat( LPCSTR szSeparator = ",", LPCSTR szDecimalPoint = "." );
void NumFormatLPSTR( LPSTR szFormat, LPSTR szFResult, double dValue, LPCSTR szDecimalPoint = ".", LPCSTR szThousandSeparator = ",");
};
// -----------------------------------------------------------------------------------------------------------------------------------------------------------
// CTim, the CTime extension ( NEW 2.0 ), see CSTR
// -----------------------------------------------------------------------------------------------------------------------------------------------------------
#ifndef _CTIM
#define _CTIM
#endif
#ifndef _CTIM20
#define _CTIM20
#endif
#define CTIME_OK 0
#define CTIME_OVERFLOW 1
#define CTIME_NOTVALID 2
class CTim : public CTime
{
public:
CTim( void ) : CTime(1980, 1, 1, 0, 0, 0) {}; // we can' t use the standard constructor...
CTim( const CTime& timeSrc ) : CTime( timeSrc ) {};
CTim( time_t time ) : CTime( time ) {};
CTim( int nYear, int nMonth, int nDay, int nHour = 0, int nMin = 0, int nSec = 0 ): CTime( nYear, nMonth, nDay, nHour, nMin, nSec ) {};
CTim( WORD wDosDate, WORD wDosTime ) : CTime( wDosDate, wDosTime ) {};
int Build( int iYear, int iMonth, int iDay, int iHour = 0, int iMin = 0, int iSec = 0 );
BOOL FromFile( LPCSTR szFile );
BOOL SetDay( int iDay = 1 ); //All these methods change the current CTim object...
BOOL SetDay( LPCSTR szDay );
BOOL SetMonth( int iMonth = 1 );
BOOL SetMonth( LPCSTR szMonth );
BOOL SetYear( int iYear );
BOOL SetYear( LPCSTR szYear );
BOOL SetSec( int iSec = 0 );
BOOL SetSec( LPCSTR szSec );
BOOL SetMin( int iMin = 0 );
BOOL SetMin( LPCSTR szMin );
BOOL SetHour( int iHour = 23 );
BOOL SetHour( LPCSTR szHour );
BOOL IncDay( int iDay = 1 );
BOOL IncSec( int iSec = 1 );
BOOL IncMin( int iMin = 1 );
BOOL IncHour( int iHour = 1 );
BOOL IsLeapYear( ) const;
BOOL IsLastDay() const; // last day of the month
};